package edu.ua.cs.cs515.gcj.tetris;

/**
 * Provides an interface between the model and the user.  Allows for certain elements
 * of the model to be manipulated.
 */
public class TetrisController {
	
	private TetrisModel model = null;
	
	// Set the model
	public void setModel(TetrisModel model) {
		this.model = model;
	}
	
	// Move the tetromino left
	public void moveLeft() {
		if (this.model != null) {
			model.decrementPosX();
		}
	}
	
	// Move the tetromino right
	public void moveRight() {
		if (this.model != null) {
			model.incrementPosX();
		}
	}
	
	// Drop the current falling block
	public void dropBlock() {
		if (this.model != null) {
			model.dropBlock();
		}
	}
	
	// Speed the tetromino up
	public void setSpeedUp() {
		int speedup=0;
		switch (model.getDifficulty()) {
		case 'E':
			speedup = TetrisModel.EASY_DELAY-50;
			break;
		case 'M':
			speedup = TetrisModel.MEDIUM_DELAY-40;
			break;
		case 'H':
			speedup = TetrisModel.HARD_DELAY-30;
			break;
		case 'I':
			speedup = TetrisModel.INSANE_DELAY;
			break;
		}
		if (this.model != null) {
			model.setSpeedUp(speedup);
		}
	}
	
	// Resume normal speed
	public void unSetSpeedUp() {
		if (this.model != null) {
			model.setSpeedUp(0);
		}
	}
	
	// Rotate the tetromino
	public void rotate() {
		if (this.model != null) {
			model.rotateTetromino();
		}
	}
	
	// Start the game
	public void startGame() {
		if (this.model != null) {
			model.triggerGame();
		}
	}
	
	// Pause and resume the game
	public void pauseResume() {
		if (this.model != null) {
			model.pauseResumeGame();
		}
	}
	
	public void setDifficulty(char difficulty) {
		if (model != null) {
			model.setDifficulty(difficulty);
		}
	}
	
	public int getScore() {
		if (model != null) {
			return model.getScore();
		}
		return 0;
	}
	
	public boolean isGameRunning() {
		if (model != null) {
			return model.isGameActive();
		}
		return false;
	}
	
	public void endGame() {
		if (model != null) {
			if (model.isGameActive()) {
				model.endGame();
			}
		}
	}
	
	public void muteSound(boolean muted) {
		if (model != null) {
			model.muteSound(muted);
		}
	}

}
